import http from './../../../base/api/public'
import querystring from 'querystring'
import template from "vue-resource/src/url/template";

let sysConfig = require('@/../config/sysConfig')
let apiUrl = sysConfig.sfsApiUrlPre;

/**
 * 分页获取用户信息列表
 * @param page
 * @param size
 * @param params
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_list = (page, size, params) => {
  //将json数据params拼接为k-v对
  let stringify = querystring.stringify(params);
  //转发请求url
  return http.requestQuickGet(apiUrl + '/ucenter/user/list/' + page + '/' + size + '?' + stringify)
};

/**
 * 根据用户id获取用户信息
 * @param id
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_get = id => {
  return http.requestQuickGet(apiUrl + '/ucenter/user/get/' + id)
};

/**
 * 编辑用户信息
 * @param id
 * @param params
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_edit = (id, params) => {
  return http.requestPut(apiUrl + '/ucenter/user/edit/' + id, params)
};

/**
 * 删除用户
 * @param id
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_delete = (id) => {
  return http.requestDelete(apiUrl + '/ucenter/user/delete/' + id);
};

/**
 * 用户授权，设置角色
 * @param userId
 * @param roleIds
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_setrole = (userId, roleIds) => {
  return http.requestPost(apiUrl + '/ucenter/user/setrole/' + userId + '?roleIds=' + roleIds);
};

/**
 * 修改密码
 * @param userId
 * @param password
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_editPwd = (userId, password) => {
  return http.requestPut(apiUrl + '/ucenter/user/editPwd/' + userId + '?password=' + password);
};


/**
 * 获取角色列表
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_roleList = () => {
  //转发请求url
  return http.requestQuickGet(apiUrl + '/ucenter/role/findlist/')
};

/**
 * 根据用户id获取用户拥有的角色列表
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_getUserRole = (userId) => {
  //转发请求url
  return http.requestQuickGet(apiUrl + '/ucenter/role/getUserRole/' + userId)
};

/**
 * 获取角色列表
 * @param page
 * @param size
 * @param roleName
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const role_list = (page, size, roleName) => {
  //转发请求url
  return http.requestQuickGet(apiUrl + '/ucenter/role/list/' + page + '/' + size + '/?roleName=' + roleName)
};


/**
 * 获取权限列表
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const getMenuList = () => {
  //转发请求url
  return http.requestQuickGet(apiUrl + '/ucenter/menu/list/')
};

/**
 * 获取角色拥有的权限
 * @param roleId
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const user_getRoleMenu = (roleId) => {
  //转发请求url
  return http.requestQuickGet(apiUrl + '/ucenter/menu/getRoleMenu/' + roleId)
};

/**
 * 角色授权
 * @param roleId
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const role_setMenu = (roleId, params) => {
  //转发请求url
  return http.requestPost(apiUrl + '/ucenter/role/setMenu/' + roleId + '?menuIds=' + params);
};

/**
 * 角色删除
 * @param roleId
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const role_delete = (roleId) => {
  return http.requestDelete(apiUrl+'/ucenter/role/delete/'+roleId);
};

/**
 * 角色编辑
 * @param id
 * @param params
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const role_edit = (id, params) => {
  return http.requestPut(apiUrl + '/ucenter/role/edit/' + id, params)
};

/**
 * 角色添加
 * @param params
 * @returns {*|Promise|Promise<unknown>|Promise}
 */
export const role_add=(params)=>{
  return http.requestPost(apiUrl+'/ucenter/role/add',params);
};


export const role_get=(id)=>{
  return http.requestGet(apiUrl+'/ucenter/role/get/'+id);
};
